local skill = fk.CreateSkill{
  name = "action__shenbing_skill",
}

Fk:loadTranslationTable{
  ["action__shenbing"] = "神兵",
  ["action__shenbing_skill"] = "神兵",
  [":action__shenbing"] = "锦囊牌<br /><b>时机</b>：出牌阶段<br /><b>目标</b>：你 <br /><b>效果</b>：令所有角色弃置装备区所有牌或依次使用牌堆中不同类型的装备牌各一张。（不可响应）",
  ["#action__shenbing_skill"] = "令所有角色弃置装备区所有牌或依次使用牌堆中不同类型的装备牌各一张",
  ["#action__shenbing_discard"] = "令所有角色弃置装备区所有牌",
  ["#action__shenbing_usecard"] = "令所有角色依次使用牌堆中不同类型的装备牌各一张",
}


skill:addEffect("cardskill", {
  mute = true,
  name = "action__shenbing",
  prompt = "#action__shenbing_skill",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    cardUseEvent.disresponsiveList = table.simpleClone(Fk:currentRoom().players)
    if not cardUseEvent.tos or #cardUseEvent.tos == 0 then
      cardUseEvent.tos = { cardUseEvent.from }
    end
  end,
  on_effect = function(self, room, effect)
    local choice = room:askToChoice(effect.to, {
      choices= {"#action__shenbing_discard", "#action__shenbing_usecard"},
      skill_name = self.name,
      cancelable = false,
      prompt = "请选择一项",
    })
    if choice == "#action__shenbing_discard" then
      for _, p in ipairs(room.alive_players) do
        if #p:getCardIds("e") > 0 then
          p:throwAllCards("e")
        end
      end
    else
      for _, p in ipairs(room.alive_players) do
        local subs = {
          [Player.WeaponSlot] = Card.SubtypeWeapon,
          [Player.ArmorSlot] = Card.SubtypeArmor,
          [Player.DefensiveRideSlot] = Card.SubtypeDefensiveRide,
          [Player.OffensiveRideSlot] = Card.SubtypeOffensiveRide,
          [Player.TreasureSlot] = Card.SubtypeTreasure
        }
        local has = table.simpleClone(p.equipSlots)
        for _, no in ipairs(p.sealedSlots) do
          table.removeOne(has, no)
        end
        local subtypes = {}
        for _, e in ipairs(has) do
          if subs[e] then
            table.insert(subtypes, subs[e])
          end
        end
        if #subtypes == 0 then
          return
        end
        local subtype
        local cards = {}
        local card
        while #subtypes > 0 and not p.dead do
          subtype = table.remove(subtypes, 1)
          if p:hasEmptyEquipSlot(subtype) then
            cards = table.filter(room.draw_pile, function(id)
              card = Fk:getCardById(id)
              return card.sub_type == subtype
            end)
            if #cards > 0 then
              room:useCard {
                from = p,
                tos = { p },
                card = Fk:getCardById(cards[math.random(1, #cards)]),
              }
            end
          end
        end
      end
    end
  end,
})


return skill